package com.kgc.onlineLife.controller;

import com.kgc.onlineLife.bean.User;
import com.kgc.onlineLife.service.ForeService;
import com.kgc.onlineLife.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Map;

/**
 * Created On : 2022/4/20.
 * <p>
 * Author     : 张冲
 * <p>
 * Description: DashboardController
 */
@Controller
@RequestMapping("/admin")
public class DashboardController {

    @Autowired
    private ForeService foreService;



    @RequestMapping("/dashboard")
    public String index(HttpServletRequest request,
                        Model model){
                /**
                 * 最近七天收入
                 */
                Double totalIncome1 = foreService.TotalIncome1();
                Double totalIncome2 = foreService.TotalIncome2();
                Double totalIncome3 = foreService.TotalIncome3();
                Double totalIncome4 = foreService.TotalIncome4();
                Double totalIncome5 = foreService.TotalIncome5();
                Double totalIncome6 = foreService.TotalIncome6();
                Double totalIncome7 = foreService.TotalIncome7();

                /**
                 * 今日订单
                 */
                Integer orders = foreService.todayOrder();

                /**
                 * 用户总数
                 */
                Integer customers = foreService.TotalCustomer();

                /**
                 * 评论数
                 */
                Integer comments = foreService.TotalComment();

                model.addAttribute("totalIncome1",totalIncome1);
                model.addAttribute("totalIncome2",totalIncome2);
                model.addAttribute("totalIncome3",totalIncome3);
                model.addAttribute("totalIncome4",totalIncome4);
                model.addAttribute("totalIncome5",totalIncome5);
                model.addAttribute("totalIncome6",totalIncome6);
                model.addAttribute("totalIncome7",totalIncome7);
                request.setAttribute("orders",orders);
                model.addAttribute("customers",customers);
                request.setAttribute("comments",comments);


                /**
                 *获取最近七天
                 */
                SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
                String date1 = sdf.format(foreService.getday1());
                String date2 = sdf.format(foreService.getday2());
                String date3 = sdf.format(foreService.getday3());
                String date4 = sdf.format(foreService.getday4());
                String date5 = sdf.format(foreService.getday5());
                String date6 = sdf.format(foreService.getday6());
                String date7 = sdf.format(foreService.getday7());

                model.addAttribute("date1",date1);
                model.addAttribute("date2",date2);
                model.addAttribute("date3",date3);
                model.addAttribute("date4",date4);
                model.addAttribute("date5",date5);
                model.addAttribute("date6",date6);
                model.addAttribute("date7",date7);

                /**
                 * 最近七天交易量
                 */
                Integer orderQuantity1 = foreService.orderCount1();
                Integer orderQuantity2 = foreService.orderCount2();
                Integer orderQuantity3 = foreService.orderCount3();
                Integer orderQuantity4 = foreService.orderCount4();
                Integer orderQuantity5 = foreService.orderCount5();
                Integer orderQuantity6 = foreService.orderCount6();
                Integer orderQuantity7 = foreService.orderCount7();

                model.addAttribute("orderQuantity1",orderQuantity1);
                model.addAttribute("orderQuantity2",orderQuantity2);
                model.addAttribute("orderQuantity3",orderQuantity3);
                model.addAttribute("orderQuantity4",orderQuantity4);
                model.addAttribute("orderQuantity5",orderQuantity5);
                model.addAttribute("orderQuantity6",orderQuantity6);
                model.addAttribute("orderQuantity7",orderQuantity7);

                return "Admin/index";
                

    }
    
    
    
    
}
